const { defineConfig } = require('@vue/cli-service');
const path = require('path');
const fs = require('fs');

// 从项目根目录读取配置
const configPath = path.resolve(__dirname, 'public/config.json');
const rawData = fs.readFileSync(configPath, 'utf-8');
const { server } = JSON.parse(rawData);

module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    proxy: {
      '/api': {
        target: `http://${server.ip}:${server.backendPort}`,
        changeOrigin: true,
        pathRewrite: { '^/api': '' }
      }
    },
    host: '0.0.0.0',
    port: server.frontendPort,
    allowedHosts: "all",
    client: {
      overlay: {
        runtimeErrors: (error) => {
          const ignoreList = ["ResizeObserver loop completed with undelivered notifications."];
          return !ignoreList.includes(error.message);
        },
      },
      webSocketURL: `auto://0.0.0.0:${server.frontendPort}/ws`
    }
  }
});